# coding:utf-8
import os
import sqlite3
from xpinyin import Pinyin

__author__ = 'gongqf'
print os.getcwd()
if os.path.exists(r'e:\web\flask\topshipping'):
    os.chdir(r'e:\web\flask\topshipping')
elif os.path.exists(r'l:\web\flask\topshipping'):
    os.chdir(r'l:\web\flask\topshipping')
elif os.path.exists(r'g:\web\flask\topshipping'):
    os.chdir(r'g:\web\flask\topshipping')

p=Pinyin()
conn=sqlite3.connect('topshipping.db3')
#conn.text_factory = str
hzs=conn.execute("select linename from line").fetchall()
#hzs=conn.execute("select piername from pier").fetchall()

for hz in hzs:
    print hz[0]
#    py=p.get_pinyin(hz[0],' ')
    py=p.get_pinyin_initials(hz[0])

    print py
    conn.execute("update line set linenamepys=? where linename=?",(py,hz[0]))
#    conn.execute("update pier set piernamepy=? where piername=?",(py,hz[0]))

conn.commit()
conn.close()

print p.get_pinyin('123',' ')